<template>
  <div>
      <h2>地址添加</h2>

    <div class="block"   />
  <van-address-edit
  :area-list="areaList"
  show-postal
  show-delete
  show-set-default
  show-search-result
  :search-result="searchResult"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave"
  @delete="onDelete"
  @change-detail="onChangeDetail"
/>
  </div>
</template>
<script>
import { mapGetters, mapActions} from 'vuex';
import { Toast } from 'vant';
import { areaList } from '@vant/area-data';
import {addressAdd} from "../../request/api"

export default {
  props: [],
  components: {},
  data() {
    return {
        userInfo:sessionStorage.getItem("token")?JSON.parse(sessionStorage.getItem("token")):{},

      //省市区 列表
      areaList,
      //切换默认地址时 触发
      searchResult: [],
    };
},
  computed: {
    ...mapGetters({}),
},
  methods: {
    ...mapActions({}),
    onSave(content) {
    addressAdd({uid:this.userInfo.uid,username:content.name,userphone:content.tel,location:content.province+content.city+content.county,useraddress:content.addressDetail,status:0}).then(res=>{
        if(res.data.code==200){
            Toast(res.data.msg);
            this.$router.push("/address")
        }else{
            Toast(res.data.msg);
        }
    })
    },
    onDelete() {
      Toast('delete');
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
},
  mounted() {},
};
</script>
<style scoped>
</style>